<%--
  Created by IntelliJ IDEA.
  User: wujia
  Date: 2017/7/19
  Time: 18:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script type="text/javascript" src="../../static/common/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="../../static/common/jquery/jquery-1.11.1.min.js"></script>
    <link rel="stylesheet" href="../../static/common/layui/css/layui.css">
    <script src="../../static/common/axios.min.js"></script>
    <script src="../../static/common/vue.min.js"></script>
    <script src="../../static/common/layui/layui.js"></script>
    <script>
        var  userId = ${sessionScope.currentUser.getId()};
    </script>
</head>

<div style="margin: 15px;" v-cloak>

    <div v-show="show" id="Vue">
        <form action="" method="post" class="layui-form">
            <blockquote class="layui-elem-quote">
                <div class="layui-form-item">
                    <div class="layui-input-inline">
                        <select id="composor_select" name="composor_select" class="layui-input" lay-filter="composor_select" lay-search>
                            <option value="">选择学生</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select id="isAppraise" name="isAppraise" class="layui-input" lay-filter="isAppraise" lay-search>
                            <option value="">是否已评价</option>
                            <option value="1">未评价</option>
                            <option value="2">已评价</option>
                        </select>
                    </div>
                    <input type="button" class="layui-btn" value="筛选" @click="select">
                    <input type="reset" class="layui-btn" value="重置" @click="reset">
                </div>
            </blockquote>
        </form>
        <fieldset class="layui-elem-field">
            <legend>实习日志审核</legend>
            <div class="layui-field-box layui-form">
                <table class="layui-table admin-table">
                    <thead>
                    <tr>
                        <th>日志撰写者</th>
                        <th>撰写日期</th>
                        <th>实习单位</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <%--内容容器--%>
                    <tbody id="content">
                    </tbody>
                </table>
            </div>
        </fieldset>

        <%--分页容器--%>
        <div class="admin-table-page">
            <div id="paged" class="page">
            </div>
        </div>
    </div>

    <div style="display: none" id="show_false">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>日志详情</legend>
        </fieldset>
        <form class="layui-form" >
            <div class="layui-form-item">
                <label class="layui-form-label">日志撰写人</label>
                <div class="layui-input-inline">
                    <input class="layui-input" id="composor" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">日志详情</label>
                <div class="layui-input-inline" id="hello">
                    <%--<textarea class="layui-textarea-inline"></textarea>--%>
                </div>
            </div>
            <div class="" style="margin-bottom: 15px;">
                <label class="layui-form-label">评价内容</label>
                <div class="layui-input-block" id="edit" style="display: none">
                    <textarea id="ta_ckeditor" class="ckeditor my-math" cols="20" rows="2" style="overflow:auto"></textarea>
                    <script type="text/javascript">CKEDITOR.replace('ta_ckeditor');</script>
                    <div class="layui-input-block" style="margin-top: 20px">
                        <input type="button" class="layui-btn" lay-filter="save" value="保存" lay-submit>
                        <button class="layui-btn" lay-filter="reload">返回</button>
                    </div>
                </div>
                <div class="layui-input-block" id="detail" style="display: none">
                    <div class="layui-input-inline" id="advisorappraise">
                        <%--<textarea class="layui-textarea-inline"></textarea>--%>
                    </div>
                    <div class="layui-input-block" style="margin-top: 20px">
                        <button class="layui-btn" lay-filter="reload">返回</button>
                    </div>
                </div>
            </div>
        </form>
    </div>

</div>
<!--模板-->
<script type="text/html" id="tpl">
    {{# layui.each(d.data, function(index, item){ }}
    <tr>
        <td>{{ item.user.realname || "-" }}</td>
        <td>{{getYearMonthDate(item.internLog.date)|| "-"}}</td>
        <td>
            {{# if(item.orgInfo!=null){ }}
            {{ item.orgInfo.fullname || "-"}}
            {{# }; }}
        </td>
        {{#  if(item.internLog.advisorappraise == ""){ }}
        <td> <a href="javascript:;" target="_self" data-id="{{item.internLog.id}}" data-opt="more" class="layui-btn layui-btn-normal layui-btn-mini" style="background-color: #009688;">待评价</a>
            {{#  }; }}
            {{#  if(item.internLog.advisorappraise!="" ){ }}
        <td> <a href="javascript:;" target="_self" data-id="{{item.internLog.id}}" data-opt="more" class="layui-btn layui-btn-normal layui-btn-mini">查看详情</a>
            {{#  }; }}
    </tr>
    {{# }); }}
</script>
<script>
    var  teacher={};
    axios.get('/teacherInfo/findOneDetail/'+userId)
        .then(function (response) {
//            console.log(response.data.data);
            teacher = response.data.data.teacherInfo;
        })
        .catch(function (msg) {
            console.log(msg);
        });
</script>
<script >
    /**
     * 时间格式取年月日
     * @param time
     * @returns {*}
     */
    function getYearMonthDate(time) {
        if(time!=null) {
            var YMD = time.split(" ")[0];  // 年月日
            var HMS = time.split(" ")[1];  // 时分秒
            return YMD;
        }
        return null;
    }
    layui.config({
        base: '/static/js/layuiModulesEX/'
    });
    layui.use(['paging','form','layedit'], function() {
        var $ = layui.jquery,
            paging = layui.paging(),
            layerTips = parent.layer === undefined ? layui.layer : parent.layer, //获取父窗口的layer对象
            layer = layui.layer, //获取当前窗口的layer对象
            form = layui.form();
        var layedit = layui.layedit;
        //构建一个默认的编辑器
        var index = layedit.build('LAY_demo1');
        paging.init({
            openWait: true,
            url:'/internlog/findDetailBatchByInternAdvisorCondition',
            elem: '#content', //内容容器
            params: { //发送到服务端的参数
                internAdvisorUserId:teacher.userid,
                internLog:{}
            },
            contentType : "application/json; charset=utf-8",
            type: 'POST',
            tempElem: '#tpl', //模块容器
            pageConfig: { //分页参数配置
                elem: 'paged', //分页容器
                pageSize: 10 //分页大小
            },
            success: function() { //渲染成功的回调
                //alert('渲染成功');
            },
            fail: function(msg) { //获取数据失败的回调
                //alert('获取数据失败')
            },
            complate: function() { //完成的回调
                //alert('处理完成');
                //绑定所有编辑按钮事件
                $('#content').children('tr').each(function() {
                    //获取每行记录的id值
                    var $that = $(this).children('td:last-child');
                    var id_more = $that.children('a[data-opt=more]').data('id');

                    // 详情
                    $that.children('a[data-opt=more]').on('click', function() {
                        vm.show = false;
                        $('#show_false').show();
                        axios.get('/internlog/findById/'+id_more)
                            .then(function (response) {
                                console.log(response.data.data);
                                vm.internlog = response.data.data.internLog;
                                vm.orgInfo =  response.data.data.orgInfo;
                                if(vm.internlog.advisorappraise!==""){
                                    $('#detail').show();
//                                    $('#show_false').hide();
                                    $('#edit').hide();
                                }
                                else{
                                    $('#edit').show()
                                }
                                axios.get('/user/findOneById/'+vm.internlog.composerid)
                                    .then(function (response) {
                                        console.log(response.data.data);
                                        vm.user = response.data.data;
                                        $('#composor').val(vm.user.realname);
                                    })
                                    .catch(function (msg) {
                                        console.log(msg);
                                    });
                                var divshow = $("#hello");
                                divshow.text("");// 清空数据
                                divshow.html(vm.internlog.content); // 添加Html内容，不能用Text 或 Val
                                $("#advisorappraise").text("");// 清空数据
                                $("#advisorappraise").html(vm.internlog.advisorappraise);
                            })
                            .catch(function (response) {
                                console.log(response);
                            });

                    });
                });

            }
        });
        var vm = new Vue({
            el:'#Vue',
            data:{
                show:true,
                internlog:{},
                user:{},
                orgInfo:{}
            },
            methods:{
                select:function () {
                    var composerid = $('#composor_select').val();
                    var isEvaluation = $('#isAppraise').val();
                    console.log('isEvaluation:'+isEvaluation);
                    paging.get({
                        internAdvisorUserId:teacher.userid,
                        internLog:{
                            composerid:composerid,
                            isEvaluation:isEvaluation
                        }
                    });
                },
                reset:function () {
                    paging.get({
                        internAdvisorUserId:teacher.userid,
                        internLog:{
                            isEvaluation:'',
                            composerid:''
                        }
                    });
                }
            }
        });

        axios.get('/student/findBatchByInternAdvisorUserId/'+ userId)
            .then(function (response) {
                console.log(response.data.data);
                var array = response.data.data;
                var html = '';
                for(var i in array){
                    html += '<option value='+array[i].id+'>'+array[i].realname+'</option>';
                }
                $('#composor_select').append(html);
                form.render('select');
            })
            .catch(function (msg) {
                console.log(msg);
            })

        form.on('submit(save)',function (data) {
//            console.log(CKEDITOR.instances.ta_ckeditor.getData());
            vm.internlog.advisorappraise = CKEDITOR.instances.ta_ckeditor.getData();
            vm.internlog.isEvaluation = 2;
//            console.log(vm.internlog);
            axios.post('/internlog/modify',vm.internlog)
                .then(function (response) {
                    if(response.data.success){
                        layer.msg("评价成功",{icon:1,time:1500},function () {
                            paging.get();
                            vm.show = true;
                            $('#show_false').hide();
                        });
                    }
                })
                .catch(function (msg) {
                    console.log(msg);
                });
        });

        form.on('button(reload)',function () {
           vm.show = true;
           $('#show_false').hide();
        });
    });

</script>


</body>
</html>
